﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ISHotelApp.Database;

namespace ISHotel_WinForm
{
    public partial class SluzbyForm : Form
    {
        public SluzbyForm()
        {
            InitializeComponent();

            SluzbaTable sluzbaTable = new SluzbaTable();
            dataGridViewSluzby.AutoGenerateColumns = false;

            DataGridViewTextBoxColumn idSluzbyColumn = new DataGridViewTextBoxColumn();
            idSluzbyColumn.DataPropertyName = "id_sluzby";
            idSluzbyColumn.HeaderText = "ID Sluzby";

            DataGridViewTextBoxColumn nazevSluzbyColumn = new DataGridViewTextBoxColumn();
            nazevSluzbyColumn.DataPropertyName = "nazev_sluzby";
            nazevSluzbyColumn.HeaderText = "Nazev sluzby";

            DataGridViewTextBoxColumn popisSluzbyColumn = new DataGridViewTextBoxColumn();
            popisSluzbyColumn.DataPropertyName = "popis_sluzby";
            popisSluzbyColumn.HeaderText = "Popis sluzby";

            DataGridViewTextBoxColumn cenaSluzbyColumn = new DataGridViewTextBoxColumn();
            cenaSluzbyColumn.DataPropertyName = "cena_sluzby";
            cenaSluzbyColumn.HeaderText = "Cena sluzby";

            dataGridViewSluzby.DataSource = sluzbaTable.Select();

            dataGridViewSluzby.Columns.Add(idSluzbyColumn);
            dataGridViewSluzby.Columns.Add(nazevSluzbyColumn);
            dataGridViewSluzby.Columns.Add(popisSluzbyColumn);
            dataGridViewSluzby.Columns.Add(cenaSluzbyColumn);

        }

        private void dataGridViewSluzby_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            ErrLabel.Text = "";
            if (e.RowIndex >= 0)
            {
                int id_sluzby = (int)dataGridViewSluzby.Rows[e.RowIndex].Cells[0].Value;
                SluzbaTable sluzbaTable = new SluzbaTable();
                Sluzba sluzba = sluzbaTable.Select(id_sluzby);
                IDSluzbyTB.Text = sluzba.id_sluzby.ToString();
                NazevSluzbyTB.Text = sluzba.nazev_sluzby;
                PopisSluzbyTB.Text = sluzba.popis_sluzby;
                CenaSluzbyTB.Text = sluzba.cena_sluzby.ToString();
            }
        }
    }
}
